﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FreeDAM.Domain.Abstract;
using FreeDAM.Domain.Entities;

namespace FreeDAM.WebUI.Areas.Admin.Controllers
{
    public class FilesController : Controller
    {
        private readonly IRenditionRepository RenditionRepository;
        private readonly IAssetRepository AssetRepository;

        public FilesController(IRenditionRepository renditionRepository, IAssetRepository assetRepository)
        {
            RenditionRepository = renditionRepository;
            AssetRepository = assetRepository;
        }

        // seperating out thumbnail from display since we don't need to / want to track thumbnail hits
        public FileResult Thumbnail(int id)
        {
            Rendition rendition = RenditionRepository.Find(id);
            FileStream stream = new FileStream(rendition.DirectoryLocation, FileMode.Open);
            return File(stream, rendition.MimeType, rendition.FileName);
        }

        public FileResult DisplayRendition(int id)
        {
            // need to add hit count logic
            Rendition rendition = RenditionRepository.Find(id);
            //FileStream stream = new FileStream(, FileMode.Open);
            return File(rendition.DirectoryLocation, rendition.MimeType, rendition.FileName);
            //return File(stream, rendition.MimeType, rendition.FileName);
        }

        public FileStreamResult DisplayNative(int id)
        {
            // need to add hit count logic
            Asset asset = AssetRepository.Find(id);
            FileStream stream = new FileStream(asset.DirectoryLocation, FileMode.Open);
            return File(stream, asset.MimeType, asset.FileName);
        }
    }
}
